package com.tencent.iov.cowin.befsale.clue.crypt.config;

import com.tencent.iov.cowin.befsale.clue.component.MaskComponent;
import com.tencent.cloud.iov.common.api.DataMaskingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @Author: Caychen
 * @Date: 2022/2/16 14:57
 * @Description:
 */
@Configuration
public class CustomCryptConfig {
    
    @Bean
    public MaskComponent maskComponent(){
        return new MaskComponent(new DataMaskingService());
    }

    @Bean
    @ConditionalOnProperty(name = "db.encrypt.enabled", havingValue = "true", matchIfMissing = true)
    public CustomCryptInterceptor customCryptInterceptor(@Autowired MaskComponent maskComponent) {
        CustomCryptInterceptor cryptInterceptor = new CustomCryptInterceptor(maskComponent);
        Properties properties = new Properties();
        properties.setProperty("dialect", "mysql");
        cryptInterceptor.setProperties(properties);
        return cryptInterceptor;
    }

}
